package com.wuchao.spring.aopPlus.theaspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * @Author wuchao66
 * @Date 2022/9/27 16:15
 * @PackageName:com.wuchao.spring.aopPlus.theaspect
 * @ClassName: TheAspect
 * @Description: TODO
 * @Param
 * @Version 1.0
 */
@Aspect//标注为切面
@Slf4j
@Service//最容易忘记，又不报错
public class TheAspect {//切面，也就是增强方法所在的类型
    //标注增强处理类
    @Before(value = "execution(* com.wuchao.spring.aopPlus.point.*.*())")
    public void before(JoinPoint jp) {
        log.info("我是切面中的前置增强");
        log.info("调用" + jp.getTarget() + "的" + jp.getSignature().getName() + "方法。方法入参:" + Arrays.toString(jp.getArgs()));
    }
    @AfterReturning(value = "execution(* com.wuchao.spring.aopPlus.point.*.*())")
    public void afterReturning(JoinPoint jp) {
        log.info("我是切面中的后置增强");
        log.info("调用" + jp.getTarget() + "的" + jp.getSignature().getName() );
    }
    //报错
    @AfterThrowing(value = "execution(* com.wuchao.spring.aopPlus.point.*.*())")
    public void afterThrowing() {
        log.info("我是切面中的报错增强");

    }
    //报finally  around 你回去自己写
    @After(value = "execution(* com.wuchao.spring.aopPlus.point.*.*())")
    public void after(JoinPoint jp) {
        log.info("我是切面中的finally增强");

    }
}
